import { ref, watch } from "vue";
import { formatUnit } from "@/utils/format";
import { getSystemResourceDetail, getTopologyResourceDetail } from "@/api/topoNodeDetail";

export default function useResourceInfo({ node, queryTime, apiType }) {
  const workloadInfo = ref({});
  // * 获取工作负载详情
  const getWorkloadInfo = (params, apiType) => {
    const promise =
      apiType === "system"
        ? getSystemResourceDetail(params)
        : getTopologyResourceDetail(params);
    promise.then((res) => {
      workloadInfo.value = res.data || {};
    });
  };
  const vmInfoList = [
    {
      title: "CPU使用量",
      dataIndex: "cpuUsage",
      unit: '核',
      render: (text) => formatUnit(text, "核"),
    },
    {
      title: "内存使用量",
      dataIndex: "memoryUsage",
      unit: 'byteMin',
      render: (text) => formatUnit(text, "byteMin"),
    },
    {
      title: "磁盘使用量",
      dataIndex: "fsUsage",
      unit: 'byteMin',
      render: (text) => formatUnit(text, "byteMin"),
    },
  ];
  const firstInfoList = [
    {
      title: "CPU使用量",
      dataIndex: "cpuUsage",
      unit: '核',
      render: (text) => formatUnit(text, "核"),
    },
    {
      title: "CPU Request",
      dataIndex: "cpuRequest",
      unit: '核',
      render: (text) => formatUnit(text, "核"),
    },
    {
      title: "CPU Limit",
      dataIndex: "cpuLimit",
      unit: '核',
      render: (text) => formatUnit(text, "核"),
    },
    {
      title: "磁盘使用量",
      dataIndex: "fsUsage",
      unit: 'byteMin',
      render: (text) => formatUnit(text, "byteMin"),
    },
  ];
  const secondInfoList = [
    {
      title: "内存使用量",
      dataIndex: "memoryUsage",
      unit: 'byteMin',
      render: (text) => formatUnit(text, "byteMin"),
    },
    {
      title: "内存 Request",
      dataIndex: "memoryRequest",
      unit: 'byteMin',
      render: (text) => formatUnit(text, "byteMin"),
    },
    {
      title: "内存 Limit",
      dataIndex: "memoryLimit",
      unit: 'byteMin',
      render: (text) => formatUnit(text, "byteMin"),
    },
    {
      title: "Pod启动率",
      dataIndex: "podStartedRate",
      unit: '%',
      render: (text) => formatUnit(text, "%"),
    },
  ];

  return {
    workloadInfo,
    vmInfoList,
    firstInfoList,
    secondInfoList,
    getWorkloadInfo,
  };
}
